package com.turman.coroutionsample.viewmodel

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import com.turman.coroutionsample.net.RetrofitClient
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn

class GithubViewModel(app: Application) : AndroidViewModel(app) {
    fun searchGithubProjects(key: String) = flow {
        val result = RetrofitClient.githubservice.searchRepositors(key)
        emit(result.items)
    }.catch { it.printStackTrace() }.flowOn(Dispatchers.IO)

}